# 管理员模型
from .base import BaseModel
from .database import db
from datetime import datetime

class Admin(BaseModel):
    __tablename__ = 'admins'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='管理员ID（自增主键）')
    phone = db.Column(db.String(20), nullable=False, unique=True, comment='手机号（唯一）')
    name = db.Column(db.String(50), nullable=False, comment='管理员姓名')
    head = db.Column(db.String(255), nullable=True, comment='头像URL')
    password = db.Column(db.String(255), nullable=False, comment='密码（加密存储）')
    created_at = db.Column(db.DateTime, default=datetime.now, nullable=False, comment='创建时间')
    # 移除is_deleted和updated_at字段，因为DDL中没有
    is_deleted = None
    updated_at = None

    # 重写to_dict方法，排除不需要的字段
    def to_dict(self):
        result = super().to_dict()
        result.pop('is_deleted', None)
        result.pop('updated_at', None)
        return result

    def __repr__(self):
        return f'<Admin {self.name}>'